package com.liaoye.hellocustomview.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;

import com.liaoye.hellocustomview.R;

public class BitMapView extends View {

    public BitMapView(Context context) {
        super(context);
        init();
    }

    private void init() {
        BitmapFactory.Options options1 = new BitmapFactory.Options();
        //设置只加载图片信息
        options1.inJustDecodeBounds = true;
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.scenery, options1);

        Log.i("BitMapView", "init: bitmap = " + bitmap + " outWeight = " + options1.outWidth +
                " outHeight " + options1.outHeight + " mimeType = " + options1.outMimeType);


        BitmapFactory.Options options2 = new BitmapFactory.Options();
        Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.scenery, options2);
        Log.i("BitMapView", "init: bitmap = " + bitmap2 + " weight = " + bitmap2.getWidth() +
                " height = " + bitmap2.getHeight() + " byteCount = " + bitmap2.getByteCount());

        // 假设在 1920 * 1080的设备的话 会进行缩放 缩放的比例为  480 / 320 = 1.5
        // 加载进内存的图片的宽为960,高为1200 对应的内存大小为 960 * 1200 * 4 = 4608000
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        Log.i("BitMapView", "init: displayMetrics = " + displayMetrics.toString());
    }
}
